package com.jml.juc.lock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Ticket {
    /**
     * 票
     */
    private int number = 30;
    Lock lock = new ReentrantLock(false);

    public void saleTicket(){
        //获取锁
        lock.lock();
        try {
            if(number > 0){
                System.out.println(Thread.currentThread().getName() +"\t卖出第" +(number--)+ "还剩下"+number);
            }
        } finally {
            //释放锁
            lock.unlock();
        }
    }
}
